package com.aioz.security.controller;


import com.aioz.security.aop.annotation.LogInfoAnnotation;
import com.aioz.security.common.ResponseResult;
import com.aioz.security.entity.Notify;
import com.aioz.security.service.impl.NotifyServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Aioz
 * @since 2022-10-28
 */
@RestController
@RequestMapping("/notify")
@Slf4j
public class NotifyController {

    @Resource
    private NotifyServiceImpl notifyService;

    //企业发送消息
    @PostMapping("/publish")
    @LogInfoAnnotation
    public ResponseResult publish(@RequestBody Notify notify){
        return notifyService.publish(notify);
    }

    //用户获取关注企业消息
    @GetMapping("/of/follow/{lastId}/{offset}")
    @LogInfoAnnotation
    public ResponseResult queryNotifyOfFollow(@PathVariable("lastId") Long max,
                                              @PathVariable(value = "offset") Integer offset){
        return notifyService.queryNotifyOfFollow(max,offset);
    }

    //企业查看自己发布的消息
    @PostMapping("/get/own/{id}")
    @LogInfoAnnotation
    public ResponseResult getOwnNotifies(@PathVariable Integer id){
        return notifyService.getOwnNotifies(id);
    }

    //企业删除消息
    @PostMapping("/delete/{id}")
    @LogInfoAnnotation
    public ResponseResult deleteNotify(@PathVariable Integer id){
        log.info("ID为 {} 的消息被删除",id);
        return notifyService.deleteNotifyById(id);
    }
}
